package com.larry.mr2.writable.FlowBean;

import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Reducer;

import java.io.IOException;

public class FlowReducer extends Reducer<Text,FlowBean,Text,FlowBean> {
    private FlowBean v = new FlowBean();
    @Override
    protected void reduce(Text key, Iterable<FlowBean> values, Reducer<Text, FlowBean, Text, FlowBean>.Context context) throws IOException, InterruptedException {

        int up = 0;
        int down = 0;
        int sum = 0;

        for (FlowBean flowBean : values) {
            up += flowBean.getUpFlow();
            down += flowBean.getDownFlow();
            sum += flowBean.getSumFlow();
        }

        v.setUpFlow(up);
        v.setDownFlow(down);
        v.setSumFlow(sum);

        context.write(key,v);
    }
}
